home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / oper_sys / emerald / emrldsys.lha / Language / Compiler / Builtins / phoney_Array.m < prev    next >
Encoding:
Text File  |  1990-08-16  |  5.8 KB  |  165 lines

  1. % @(#)phoney_Array.m    1.1  3/6/87
  2. %
  3. export _ArrayObject to "Builtins"
  4.  
  5. const _ArrayObject == 
  6.   immutable object _ArrayObject
  7.     export of
  8.     function of [ElementType : AbstractType] -> [result : NAT]
  9.       where
  10.     NAT ==    immutable type NAT
  11.           operation empty -> [NA]
  12. %          operation literal [Vector.of[ElementType]] -> [NA]
  13.           operation create[Integer] -> [NA]
  14.           function getSignature -> [Signature]
  15.         end NAT
  16.     NA ==    type NA
  17.           function  getElement [Integer] -> [ElementType]
  18.             % get the element indexed by index, failing if index 
  19.             % out of range.
  20.           operation setElement [Integer, ElementType]
  21.             % set the element, failing if index out of range
  22.           function  upperbound -> [Integer]
  23.             % return the highest valid index, ub.
  24.           function  lowerbound -> [Integer]
  25.             % return the lowest valid index, lb.
  26.           function  getSlice [Integer, Integer] -> [NA]
  27.             % return a new array, a, with lower bound lb, and 
  28.             % upper bound ub, such that for lb <= i <= ub:
  29.             %     self.getElement[i] == a.getElement[i]
  30.             % fail if lb or ub is out of range.
  31.           operation setSlice [Integer, Integer, NA]
  32.             % set the elements indexed by i for lb <= i <= ub, so 
  33.             % that for each such i:
  34.             %     self.getElement[i] == a.getElement[i]
  35.             % fail if lb or ub is out of range.
  36.           operation slideTo [Integer]
  37.             % change the valid indicies for self.  Assuming 
  38.             % the old indicies ranged from lb to ub, the new 
  39.             % indicies will range from i to i + ub - lb
  40.           operation addUpper [ElementType]
  41.             % extend the set of valid indicies, changing ub to 
  42.             % ub + 1, and setting the element indexed by the new
  43.             % ub to be e.
  44.           operation removeUpper -> [ElementType]
  45.             % return the element indexed by ub, after contracting 
  46.             % the set of valid indicies to lb <= i <= ub - 1.
  47.           operation addLower [ElementType]
  48.             % extend the set of valid indicies, changing lb to 
  49.             % lb - 1, and setting
  50.             % the element indexed by the new lb to be e.
  51.           operation removeLower -> [ElementType]
  52.             % return the element indexed by lb, after contracting 
  53.             % the set of valid indicies to lb + 1 <= i <= ub.
  54.           function  empty -> [Boolean]
  55.             % -> true if lb == ub + 1, which is true initially,
  56.             % since initially lb = 1, and ub = 0.
  57.           operation catenate [a : NA] -> [r : NA]
  58.             % extend the range of valid indicies from lb .. ub to 
  59.             % lb .. ub + a.length.  Set these new elements to refer
  60.             % to the elements of a so that for a.lb <= i <= a.ub, 
  61.             % where oub is the old value of self.ub:
  62.             %     a.getElement[i] == self.getElement[oub + i - 1]
  63.         end NA
  64.     ElementType *> type T end T
  65.       end where
  66.  
  67.       result <- 
  68.     immutable object aNAT
  69.       export empty, create, getSignature
  70.  
  71.       function getSignature -> [result : Signature]
  72.         result <- NA
  73.       end getSignature
  74.  
  75.       operation create[length : Integer] -> [result : NA]
  76.         result <-
  77.           object aNA
  78.         export getElement, setElement, upperbound, lowerbound, getSlice, setSlice,
  79.                slideTo, addUpper, removeUpper, addLower,
  80.                removeLower, empty, catenate
  81.  
  82.         var lb : Integer
  83.         var ub : Integer
  84. %        var vec: Vector.of[ElementType]
  85.  
  86.         function  getElement [index : Integer] -> [result : ElementType]
  87.           % get the element indexed by index, failing if index 
  88.           % out of range.
  89.           primitive 002 [result] <- [index]
  90.         end getElement
  91.         operation setElement [i : Integer, r : ElementType]
  92.           % set the element, failing if index out of range
  93.           primitive 102 [] <- [i, r]
  94.         end setElement
  95.         function  upperbound -> [r : Integer]
  96.           % return the highest valid index, ub.
  97.           primitive 202 [r] <- []
  98.         end upperbound
  99.         function  lowerbound -> [r : Integer]
  100.           % return the lowest valid index, always 1.
  101.           primitive 302 [r] <- []
  102.         end lowerbound
  103.         function  getSlice [i1 : Integer, i2 : Integer] -> [r : NA]
  104.           % return a new Vector, a, with lower bound lb, and 
  105.           % upper bound ub, such that for lb <= i <= ub:
  106.           %     self.getElement[i] == a.getElement[i]
  107.           % fail if lb or ub is out of range.
  108.           primitive 402 [r] <- [i1, i2]
  109.         end getSlice
  110.         operation setSlice [i1 : Integer, i2 : Integer, s : NA]
  111.           % set the elements indexed by i for lb <= i <= ub, so 
  112.           % that for each such i:
  113.           %     self.getElement[i] == a.getElement[i]
  114.           % fail if lb or ub is out of range.
  115.           primitive 502 [] <- [i1, i2, s]
  116.         end setSlice
  117.         operation slideTo [i : Integer]
  118.           % change the valid indicies for self.  Assuming 
  119.           % the old indicies ranged from lb to ub, the new 
  120.           % indicies will range from i to i + ub - lb
  121.           primitive 602 [] <- [i]
  122.         end slideTo
  123.         operation addUpper [e : ElementType]
  124.           % extend the set of valid indicies, changing ub to 
  125.           % ub + 1, and setting the element indexed by the new
  126.           % ub to be e.
  127.           primitive 702 [] <- [e]
  128.         end addUpper
  129.         operation removeUpper -> [r : ElementType]
  130.           % return the element indexed by ub, after contracting 
  131.           % the set of valid indicies to lb <= i <= ub - 1.
  132.           primitive 802 [] <- [r]
  133.         end removeUpper
  134.         operation addLower [e : ElementType]
  135.           % extend the set of valid indicies, changing lb to 
  136.           % lb - 1, and setting
  137.           % the element indexed by the new lb to be e.
  138.           primitive 902 [] <- [e]
  139.         end addLower
  140.         operation removeLower -> [r : ElementType]
  141.           % return the element indexed by lb, after contracting 
  142.           % the set of valid indicies to lb + 1 <= i <= ub.
  143.           primitive 1002 [r] <- []
  144.         end removeLower
  145.         function  empty -> [r : Boolean]
  146.           % -> true if lb == ub + 1, which is true initially,
  147.           % since initially lb = 1, and ub = 0.
  148.           primitive 1102 [r] <- []
  149.         end empty
  150.         operation catenate [a : NA] -> [r : NA]
  151.           % return a new vector the result of catenating the 
  152.           % elements of a to self
  153.           primitive 1202 [r] <- [a]
  154.         end catenate
  155.           end aNA
  156.       end create
  157.       operation empty -> [result : NA]
  158.         result <- aNAT.create[10]
  159.       end empty
  160.     end aNAT
  161.     end of
  162.  
  163.   end _ArrayObject
  164.